package com.yfl.tingyu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yfl.tingyu.pojo.Company;
import com.yfl.tingyu.pojo.MarriedPerson;
import com.yfl.tingyu.mapper.MarriedPersonMapper;
import com.yfl.tingyu.service.IMarriedPersonService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2020-05-31
 */
@Service
public class MarriedPersonServiceImpl extends ServiceImpl<MarriedPersonMapper, MarriedPerson> implements IMarriedPersonService {

    @Override
    public Map<String, Object> selectMarride(Integer page, Integer rows, Map<String,Object> params) {

        //创建分页对象
        Page<MarriedPerson> marriedPage = new Page<>(page,rows);

        QueryWrapper<MarriedPerson> qw=new QueryWrapper<>();
        //姓名模糊查询
        if (StringUtils.isNotBlank((String)params.get("pname"))){
            qw.like("pname",params.get("pname"));
        }
        //手机号模糊查询
        if (StringUtils.isNotBlank((String)params.get("phone"))){
            qw.like("phone",params.get("phone"));
        }


        Page<MarriedPerson> marriedPersonPage = baseMapper.selectPage(marriedPage, qw);

        Map<String, Object> map = new HashMap<>();

        map.put("total",marriedPersonPage.getTotal());
        map.put("rows",marriedPersonPage.getRecords());

        return map;
    }
}
